package com.siyougame.web.controller.socail;


import com.siyougame.common.constant.R;
import com.siyougame.common.core.controller.BaseController;
import com.siyougame.common.enums.UserTypeEnum;
import com.siyougame.convert.social.SocialUserConvert;
import com.siyougame.system.service.social.SocialUserService;
import com.siyougame.web.controller.socail.vo.SocialUserBindReqVO;
import com.siyougame.web.controller.socail.vo.SocialUserUnbindReqVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


@Api(tags = "管理后台 - 社交用户")
@RestController
@RequestMapping("/system/social-user")
@Validated
public class SocialUserController extends BaseController {

    @Resource
    private SocialUserService socialUserService;

    @PostMapping("/bind")
    @ApiOperation("社交绑定，使用 code 授权码")
    public R<Boolean> socialBind(@RequestBody @Valid SocialUserBindReqVO reqVO) {
        socialUserService.bindSocialUser(SocialUserConvert.INSTANCE.convert(getUserId(), UserTypeEnum.ADMIN.getValue(), reqVO));
        return R.createBySuccess(true);
    }

    @DeleteMapping("/unbind")
    @ApiOperation("取消社交绑定")
    public R<Boolean> socialUnbind(@RequestBody SocialUserUnbindReqVO reqVO) {
        socialUserService.unbindSocialUser(getUserId(), UserTypeEnum.ADMIN.getValue(), reqVO.getType(), reqVO.getOpenid());
        return R.createBySuccess(true);
    }

}
